﻿// ipagelink > 0 表示有翻页, url == null
// ipagelink = 0 表示无翻页, url == null
// ipagelink < 0 表示通过 url 或 mvc 跳转
function doPage(clientId, ipagelink, url) {
    if (event.keyCode == 13) {
        var obj = document.getElementById(clientId + "_PageIndex");
        var ivalue = parseInt(obj.value);
        if (url == null) {
            var postBack, ilink;
            if (ipagelink > 0) {
                if (ivalue % ipagelink == 0) {
                    ilink = ivalue / ipagelink;
                } else {
                    ilink = parseInt(ivalue / ipagelink) + 1;
                }
                postBack = ilink != 0 ? ivalue + '$' + ilink : ivalue;
            } else {
                postBack = ivalue;
            }
            __doPostBack(clientId, postBack);
        } else {
            if (ipagelink < 0) {
                url = url.replace("{0}", ivalue);
            } else {
                var ilink;
                if (ipagelink > 0) {
                    if (ivalue % ipagelink == 0) {
                        ilink = ivalue / ipagelink;
                    } else {
                        ilink = parseInt(ivalue / ipagelink) + 1;
                    }
                }
                url = url.replace("{0}", ivalue).replace("{1}", ilink);
            }
            document.location.href = url;
        }
        return false;
    }
}